package com.sgb.knowledgeshare.view.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.knowledgeshare.R;
import com.swgk.core.base.model.entity.VideoBean;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by：冯齐 on 2021/2/1 10:02
 * Description：
 */
public class LabelDetailsAdapter extends BaseRecycleAdapter<VideoBean> {

    public LabelDetailsAdapter(Context context, List<VideoBean> datas) {
        super(context, R.layout.item_share_classify, datas);
    }
    @Override
    public void convert(ItemViewHolder holder, VideoBean bean) {
        //  holder.setBinding(BR.viewModel, bean);
        DecimalFormat df = new DecimalFormat("##0.00");
        ImageView cover = holder.itemView.findViewById(R.id.cover);//封面
        TextView descriptions = holder.itemView.findViewById(R.id.description);//标题
        TextView playcounts = holder.itemView.findViewById(R.id.play_count);
        TextView laudcounts = holder.itemView.findViewById(R.id.laud_count);
        TextView tvLabel = holder.itemView.findViewById(R.id.tv_label);//标签
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.share_classify_loading)//图片加载出来前，显示的图片
                .fallback( R.mipmap.share_classify_failure) //url为空的时候,显示的图片
                .error(R.mipmap.share_classify_failure);//图片加载失败后，显示的图片
        Glide.with(context).load(bean.getCover()).apply(options).into(cover);
        descriptions.setText(bean.getTitle()+"");
        int playCountnum = bean.getPlayCount();
        if (playCountnum>9999){
            double playnum =  playCountnum/10000;
            playcounts.setText(df.format(playnum)+"w");
        }else {
            playcounts.setText(playCountnum+"");
        }
        int laudCountnum = bean.getLaudCount();
        if (laudCountnum>9999){
            double laudnum =  laudCountnum/10000;
            laudcounts.setText(df.format(laudnum)+"w赞");
        }else {
            laudcounts.setText(laudCountnum+"赞");
        }
        if (!TextUtils.isEmpty(bean.getLabelName())){
            tvLabel.setVisibility(View.VISIBLE);
            tvLabel.setText("#"+bean.getLabelName());
        }else {
            tvLabel.setVisibility(View.GONE);
        }
    }
}
